package com.cc8w;

import com.cc8w.anno.CallAnnotation;
import com.cc8w.entity.Person;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 一般 注解要和反射配套使用
 *
 */
public class App 
{
    public static void main( String[] args ) throws InvocationTargetException, IllegalAccessException {
        //Class person1 = Person.class;
        Person person = new Person(); //创建person对象

        Method[] methods = Person.class.getDeclaredMethods(); //得到所有方法

        for (Method method:methods){
            CallAnnotation annoTemp = null;

            annoTemp = method.getAnnotation(CallAnnotation.class); //得到注解对象
            System.out.println("调用方法名称:" + method.getName());
            System.out.println("注释的对象信息:" + annoTemp);
            if (annoTemp != null) { //如果注解对象不为空，将参数值设为注解的值
                method.invoke(person, annoTemp.phone());
            } else {
                method.invoke(person, "李四"); //如果注解对象为空，单独设置参数值
            }

            System.out.println();


        }



        System.out.println( "Hello World!" );
    }
}
